//////////////////////////////////////////////////////////////////////////

#ifndef _EDITPATIENTDIALOG_H_
#include "editpatientdialog.h"
#endif

//////////////////////////////////////////////////////////////////////////

#include "ui_patientdialog.h"

#ifndef _PATIENT_H_
#include "patient.h"
#endif

#ifndef _MAINWINDOW_H_
#include "mainwindow.h"
#endif

#include <QString>
#include <QDate>

//////////////////////////////////////////////////////////////////////////


EditPatientDialog::EditPatientDialog( QWidget* _parent )
: PatientDialog(_parent), m_Patient(NULL)
{
    // History number can not be modified
    m_ui->m_HistoryLineEdit->setEnabled(false);
}


//////////////////////////////////////////////////////////////////////////


EditPatientDialog::~EditPatientDialog()
{
}


//////////////////////////////////////////////////////////////////////////


void EditPatientDialog::SetPatient( Patient& _patient )
{
    // Set patient
    m_Patient = &_patient;

    // Display info about it
    m_ui->m_HistoryLineEdit->setText( QString::number(_patient.GetHistoryNumber()) );
    m_ui->m_SurnameLineEdit->setText( _patient.GetSurname() );
    m_ui->m_NameLineEdit->setText( _patient.GetName() );
    m_ui->m_SecondnameLineEdit->setText( _patient.GetSecondName() );
    m_ui->m_SurnameLineEdit->setText( _patient.GetSurname() );
    m_ui->m_BirthDateEdit->setDate( QDate::fromString(_patient.GetSurname()) );
    m_ui->m_MaleRadioButton->setChecked( _patient.GetSex() == Human::MALE );
    m_ui->m_FemaleRadioButton->setChecked( _patient.GetSex() == Human::FEMALE );
    m_ui->m_DiagnosisTextEdit->document()->setPlainText( _patient.GetDiagnosis() );
    m_ui->m_NotesTextEdit->document()->setPlainText( _patient.GetNotes() );
}


//////////////////////////////////////////////////////////////////////////


void EditPatientDialog::accept()
{
    // Call base handler
    PatientDialog::accept();

    // Update patient
    GetMainWindow()->GetDatabase().UpdatePatient(GetMainWindow()->GetCurrPatient());

    // Exit
    QDialog::accept();
}


//////////////////////////////////////////////////////////////////////////
